<?php

/**
 * LevelStudyKit form.
 *
 * @package    elearning
 * @subpackage form
 * @author     dvquan
 *Version	   1.00.00
 *updated      05/08/2010
 */
class LevelStudyKitForm extends BaseLevelStudyKitForm
{
  public function configure()
  {
  	unset( $this['created_at'],  $this['updated_at'] );
	$this->setDefaults( array('updated_at' => time() ) );
	//create thi chi set create
	if( $this->isNew() )
		$this->setDefaults( array('created_at' => time() ) );
	/*
	$this->embedI18n(array('en', 'vi'));
	$this->widgetSchema->setLabel('en', 'English');
	$this->widgetSchema->setLabel('vi', 'Vietnamese');
	*/
	$this->widgetSchema['lsk_image'] = new sfWidgetFormInputFileEditable(array(
	   'label'     => 'Image',
	   'file_src'  => '/uploads/assets/levelstudykit/'.$this->getPicPath().'/thumb_'.$this->getObject()->getLskImage(),
	   'is_image'  => true,
	   'edit_mode' => !$this->isNew(),
	   'template'  => '<div><p>%file%</p><p>%input%</p><p>%delete% %delete_label%</p></div>',
	));
	
	$this->validatorSchema['lsk_image'] = new sfValidatorFile(array(
	   'required'   => !((bool)($this->getObject()->getLskImage())),
	   'mime_types' => 'web_images',
	   'path' => sfConfig::get('sf_upload_dir').'/assets/levelstudykit/'.$this->getPicPath(),
	   'validated_file_class' => 'sfResizedFile',
	   'max_size'   => 41943040,
	));
	
	
	$this->widgetSchema['lsk_link'] = new sfWidgetFormInputFile(array(
	   'label'     => 'Document Link',
	  	));
	
	$this->validatorSchema['lsk_link'] = new sfValidatorFile(array(
	   'required'   => !((bool)($this->getObject()->getLskLink())),
	   'mime_types' => array('application/pdf','application/zip','application/vnd.ms-excel'),
	   'path' => sfConfig::get('sf_upload_dir').'/assets/doc/levelstudykit/'.$this->getPicPath(),
	   'max_size'   => 41943040,
	));
	
/*
	$this->widgetSchema['lsk_link'] = new sfWidgetFormInputFileEditable(array(
	   'label'     => 'Document Link',
	   'file_src'  => '/uploads/assets/Doc/student/'.$this->getPicPath().'/thumb_'.$this->getObject()->getLskLink(),
	   'is_image'  => true,
	   'edit_mode' => !$this->isNew(),
	   'template'  => '<div><p>%file%</p><p>%input%</p><p>%delete% %delete_label%</p></div>',
	));
	
	$this->validatorSchema['lsk_link'] = new sfValidatorFile(array(
	   'required'   => !((bool)($this->getObject()->getLskLink())),
	   'mime_types' => array('application/pdf','application/zip','application/vnd.ms-excel')
	   'path' => sfConfig::get('sf_upload_dir').'/assets/student/'.$this->getPicPath(),
	   'validated_file_class' => 'sfResizedFile',
	   'max_size'   => 41943040,
	));
*/
	$this->widgetSchema['course_id'] = new sfWidgetFormPropelChoice(array('model' => 'Course', 'add_empty' => false));
	$this->widgetSchema->moveField('course_id', 'before', 'level_id'); 
	// status process
	$levelskit = $this->getObject();
	if( $levelskit->getLskStatus() == 0 )
		$levelskit->setLskStatus(NULL);
	$this->widgetSchema['lsk_status'] = new sfWidgetFormInputCheckbox(array("value_attribute_value" => 1),array('value' => 1));
	$this->validatorSchema['lsk_status'] =  new sfValidatorInteger( array('required' => false ));
    $this->widgetSchema->setNameFormat('level_study_kit[%s]');
	$lang_current = sfContext::getInstance()->getUser()->getCulture();
	$this->languages = array($lang_current => $lang_current);
	$langs = array_keys($this->languages);
	$this->embedI18n($langs);
	foreach($this->languages as $lang => $label)
	{
	  $this->widgetSchema[$lang]->setLabel($label);
	}
	$this->validatorSchema->setOption('allow_extra_fields', true);
  }
  protected function getPicPath()
  {
	return utilities::getSpreadPathByDate($this->getObject()->getCreatedAt());
  }   

}
/*
zip --> application/zip
.gif --> image/gif
.jpg --> image/jpeg
.odp --> application/vnd.oasis.opendocument.presentation
.pdf --> application/pdf
.doc --> application/msword
.ods --> application/vnd.oasis.opendocument.spreadsheet
.xls --> application/vnd.ms-excel

*/
